#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from logging import getLogger
from watchdog.observers import Observer
from watchdog.events import *
import time


class FileEventHandler(FileSystemEventHandler):
    def __init__(self):
        FileSystemEventHandler.__init__(self)
        self.logger = getLogger()

    def on_moved(self, event):
        what = 'directory' if event.is_directory else 'file'
        self.logger.info('[{0}][{1}] moved to [{2}]'.format(what, event.src_path, event.dest_path))

    def on_created(self, event):
        what = 'directory' if event.is_directory else 'file'
        self.logger.info('[{0}][{1}] created'.format(what, event.src_path))

    def on_deleted(self, event):
        what = 'directory' if event.is_directory else 'file'
        self.logger.info('[{0}][{1}] deleted'.format(what, event.src_path))

    def on_modified(self, event):
        what = 'directory' if event.is_directory else 'file'
        self.logger.info('[{0}][{1}] modified'.format(what, event.src_path))



def file_watcher():
    observer = Observer()
    event_handler = FileEventHandler()
    observer.schedule(event_handler, r"E:\test", True)
    while True:
        time.sleep(1)
        try:
            observer.start()
            observer.join()
        except KeyboardInterrupt:
            observer.stop()


if __name__ == "__main__":
    file_watcher()
